﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    [ScriptType("SP.RecycleBinItemCollection", ServerTypeId="{9bfb60cf-1aca-484c-a845-5f2d4ef20865}")]
    public class RecycleBinItemCollection : ClientObjectCollection<RecycleBinItem>
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public RecycleBinItemCollection(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public void DeleteAll()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "DeleteAll", null);
            base.Context.AddQuery(query);
            this.EmptyCollectionData();
        }

        private void EmptyCollectionData()
        {
            List<object> data = base.Data;
            while (data.Count > 0)
            {
                data.RemoveAt(data.Count - 1);
            }
        }

        [Remote]
        public RecycleBinItem GetById(Guid id)
        {
            Dictionary<Guid, RecycleBinItem> dictionary;
            object obj2;
            if (base.ObjectData.MethodReturnObjects.TryGetValue("GetById", out obj2))
            {
                dictionary = (Dictionary<Guid, RecycleBinItem>) obj2;
            }
            else
            {
                dictionary = new Dictionary<Guid, RecycleBinItem>();
                base.ObjectData.MethodReturnObjects["GetById"] = dictionary;
            }
            RecycleBinItem item = null;
            if (!dictionary.TryGetValue(id, out item))
            {
                item = new RecycleBinItem(base.Context, new ObjectPathMethod(base.Context, base.Path, "GetById", new object[] { id }));
                dictionary[id] = item;
            }
            return item;
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (flag)
            {
                return flag;
            }
            return flag;
        }

        [Remote]
        public void RestoreAll()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "RestoreAll", null);
            base.Context.AddQuery(query);
            this.EmptyCollectionData();
        }
    }
}

